package com.weiqiao.api.repository.impl;

import com.weiqiao.api.repository.IAppuserApiRepository;
import com.weiqiao.base.dao.impl.BaseMongoDaoImpl;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author ChenYF
 * @Description
 * @Date 2020/7/27 19:28
 */
@Repository("AppuserApiRepositoryImpl")
public class AppuserApiRepositoryImpl extends BaseMongoDaoImpl implements IAppuserApiRepository {
    private final static String collectionName = "app_user_ext_";


    @Override
    public boolean addUser(int company_id, Bson bson, String json) {
        return this.updateOne(collectionName + company_id, bson, Document.parse(json), true);
    }

    @Override
    public String getAppUserByFilter(int company_id, Bson filter) {
        return this.findOne(collectionName + company_id, filter);
    }

    @Override
    public boolean updateAppUser(int company_id, Bson filter, Document doc, boolean batch) {
        if (batch) {
            return this.updateMany(collectionName + company_id, filter, doc, false);
        } else {
            return this.updateOne(collectionName + company_id, filter, doc, false);
        }
    }

    @Override
    public List<String> getUserBySort(int company_id, Bson filter, Bson sort) {
        return this.findFilterSort(collectionName + company_id, filter, sort);
    }

    @Override
    public List<String> getPageList(int company_id, Bson filter, Bson sort, int skip, int limit) {
        return super.findFilterSortSkipLimit(collectionName + company_id, filter, sort, skip, limit);
    }

    @Override
    public boolean delUser(int company_id, Bson filter) {
        return this.deleteOne(collectionName + company_id, filter);
    }

    @Override
    public int countInfoNum(int company_id, Bson filter) {
        return super.statististics(collectionName + company_id, filter);
    }
}
